package com.example.docmanagement.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * 文档响应 DTO
 * 返回文档的详细信息
 * 注：空字段不会在JSON响应中出现
 * 
 * 示例 JSON:
 * {
 * "id": 1,
 * "title": "Java入门指南",
 * "slug": "java-getting-started",
 * "summary": "适合初学者的Java教程",
 * "content": "# Java入门\n\n这是内容...",
 * "contentHtml": "
 * <h1>Java入门</h1>
 * <p>
 * 这是内容...
 * </p>
 * ",
 * "contentType": "direct",
 * "categoryId": 1,
 * "categoryName": "编程语言",
 * "tags": ["java", "入门", "教程"],
 * "status": "published",
 * "isPublic": true,
 * "version": 3,
 * "language": "zh-CN",
 * "authorId": "550e8400-e29b-41d4-a716-446655440000",
 * "author": "张三",
 * "viewCount": 1523,
 * "likeCount": 89,
 * "publishedAt": "2024-01-15T10:30:00",
 * "createdAt": "2024-01-10T08:00:00",
 * "updatedAt": "2024-01-20T14:20:00"
 * }
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL) // 空字段不序列化
@Schema(description = "文档响应数据")
public class DocumentResponse {

    /**
     * 文档ID
     * 数据库自增主键
     * 示例：1
     */
    @Schema(description = "文档ID", example = "1")
    private Long id;

    /**
     * 文档标题
     * 示例："Java入门指南"
     */
    @Schema(description = "文档标题", example = "Java入门指南")
    private String title;

    /**
     * 文档唯一标识符
     * 用于生成友好的URL
     * 示例："java-getting-started"
     */
    @Schema(description = "文档唯一标识符(slug)", example = "java-getting-started")
    private String slug;

    /**
     * 文档摘要
     * 简短描述文档内容
     * 示例："适合初学者的Java入门教程，涵盖基础语法和核心概念"
     */
    @Schema(description = "文档摘要", example = "适合初学者的Java入门教程")
    private String summary;

    /**
     * 文档原始内容
     * Markdown格式的文档内容
     * 示例："# Java入门\n\n## 第一章：环境搭建\n..."
     */
    @Schema(description = "文档原始内容(Markdown)", example = "# Java入门\n\n这是内容...")
    private String content;

    /**
     * HTML渲染后的内容
     * 将Markdown转换为HTML后的结果
     * 示例："
     * <h1>Java入门</h1>
     * <h2>第一章：环境搭建</h2>..."
     */
    @Schema(description = "HTML渲染后的内容", example = "<h1>Java入门</h1><p>这是内容...</p>")
    private String contentHtml;

    /**
     * 文档内容文件路径
     * 当内容存储在文件中时的路径
     * 示例："/docs/java/getting-started.md"
     */
    @Schema(description = "文档内容文件路径", example = "/docs/java/getting-started.md")
    private String contentPath;

    /**
     * 文档内容外部URL
     * 当内容来自外部URL时的地址
     * 示例："https://example.com/docs/java-guide.md"
     */
    @Schema(description = "文档内容外部URL", example = "https://example.com/docs/java-guide.md")
    private String contentUrl;

    /**
     * Base64编码的内容
     * 当内容以Base64方式存储时
     */
    @Schema(description = "Base64编码的内容")
    private String contentBase64;

    /**
     * 内容类型
     * 指示内容的来源方式
     * 可选值："direct"、"file"、"url"、"base64"
     * 示例："direct"
     */
    @Schema(description = "内容类型", example = "direct", allowableValues = { "direct", "file", "url", "base64" })
    private String contentType;

    /**
     * 所属分类ID
     * 关联的分类主键
     * 示例：1
     */
    @Schema(description = "所属分类ID", example = "1")
    private Long categoryId;

    /**
     * 所属分类名称
     * 用于显示，避免前端需要额外查询
     * 示例："编程语言"
     */
    @Schema(description = "所属分类名称", example = "编程语言")
    private String categoryName;

    /**
     * 标签列表
     * 用于分类和搜索
     * 示例：["java", "入门", "教程"]
     */
    @Schema(description = "标签列表", example = "[\"java\", \"入门\", \"教程\"]")
    private String[] tags;

    /**
     * 文档状态
     * 可选值：
     * - "draft": 草稿
     * - "published": 已发布
     * - "archived": 已归档
     * 示例："published"
     */
    @Schema(description = "文档状态", example = "published", allowableValues = { "draft", "published", "archived" })
    private String status;

    /**
     * 是否公开
     * true: 所有人可见
     * false: 仅作者可见
     */
    @Schema(description = "是否公开", example = "true")
    private Boolean isPublic;

    /**
     * 文档版本号
     * 每次更新自动递增
     * 用于版本控制和乐观锁
     * 示例：3（表示已更新3次）
     */
    @Schema(description = "文档版本号", example = "3")
    private Integer version;

    /**
     * 文档语言
     * ISO 639-1语言代码
     * 示例："zh-CN"（简体中文）、"en-US"（英语）
     */
    @Schema(description = "文档语言(ISO 639-1)", example = "zh-CN")
    private String language;

    /**
     * 作者用户ID
     * UUID格式
     * 示例："550e8400-e29b-41d4-a716-446655440000"
     */
    @Schema(description = "作者用户ID", example = "550e8400-e29b-41d4-a716-446655440000")
    private UUID authorId;

    /**
     * 作者用户名
     * 用于显示，避免前端需要额外查询
     * 示例："张三"
     */
    @Schema(description = "作者用户名", example = "张三")
    private String author;

    /**
     * 浏览次数
     * 记录该文档被查看的次数
     * 示例：1523
     */
    @Schema(description = "浏览次数", example = "1523")
    private Integer viewCount;

    /**
     * 点赞数量
     * 记录用户对该文档的点赞次数
     * 示例：89
     */
    @Schema(description = "点赞数量", example = "89")
    private Integer likeCount;

    /**
     * 发布时间
     * 文档首次发布的时间戳
     * 格式：ISO 8601
     * 示例："2024-01-15T10:30:00"
     */
    @Schema(description = "发布时间", example = "2024-01-15T10:30:00", type = "string", format = "date-time")
    private LocalDateTime publishedAt;

    /**
     * 创建时间
     * 文档首次创建的时间戳
     * 格式：ISO 8601
     * 示例："2024-01-10T08:00:00"
     */
    @Schema(description = "创建时间", example = "2024-01-10T08:00:00", type = "string", format = "date-time")
    private LocalDateTime createdAt;

    /**
     * 最后更新时间
     * 文档最近一次修改的时间戳
     * 格式：ISO 8601
     * 示例："2024-01-20T14:20:00"
     */
    @Schema(description = "最后更新时间", example = "2024-01-20T14:20:00", type = "string", format = "date-time")
    private LocalDateTime updatedAt;
}
